package com.manbu.live.user.provider.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.manbu.live.user.provider.dao.po.UserTagPO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author hanWang
 * @Title:
 * @Package
 * @Description:
 * @date 2024/1/2411:52 PM
 */
@Mapper
public interface IUserTagMapper extends BaseMapper<UserTagPO> {
    /**
     * 使用或的思路来设置标签,只能允许第一次设置成功
     * @param userId
     * @param filedName
     * @param tag
     * @return
     */
    @Update("update t_user_tag set ${filedName}=${filedName} | #{tag} where user_id =#{userId} and ${filedName} & #{tag} = 0")
    int setTag(@Param("userId") Long userId, @Param("filedName") String filedName, @Param("tag") long tag);
    @Update("update t_user_tag set ${filedName}=${filedName} &~ #{tag} where user_id =#{userId} and ${filedName} & #{tag} = #{tag")
    int cancelTag(Long userId, String filedName, long tag);

    @Select("select * from t_user_tag where user_id =#{userId}")
    UserTagPO selectByUserId(@Param("userId") Long userId);

}
